<?php



if (!function_exists('dr_son_url')) {
    function dr_son_url($data) {
        $config = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-fuwu', 'setting', 'param');;
        if (isset($config['son_rewrite']) && $config['son_rewrite'] && $config['son_rule']) {
            $mod = \Phpcmf\Service::C()->module;
            return \Phpcmf\Service::L('router')->get_url_value(
                $data,
                $config['son_rule'],
                \Phpcmf\Service::L('router')->url_prefix('rewrite', $mod, $data, 0)
            );
        }
        return '/index.php?s=fuwu&c=son&id='.$data['id'];
    }
}

// 是否存在中 1收藏了 2没有收藏
if (!function_exists('dr_is_son_cart')) {
    function dr_is_son_cart($dir, $id, $uid = 0)
    {

        !$uid && $uid = \Phpcmf\Service::C()->uid;
        if (!$uid) {
            return 0;
        } elseif (!$dir) {
            return 0;
        }

        return \Phpcmf\Service::M()->db->table(SITE_ID . '_' . $dir . '_cart')->where('uid', $uid)->where('cid', $id)->countAllResults();
    }
}

// 是否购买了
if (!function_exists('dr_is_son_buy')) {
    function dr_is_son_buy($dir, $id, $uid = 0)
    {

        !$uid && $uid = \Phpcmf\Service::C()->uid;
        if (!$uid) {
            return 0;
        } elseif (!$dir) {
            return 0;
        } elseif (!$id) {
            return 0;
        }

        return \Phpcmf\Service::M()->db->table(SITE_ID . '_' . $dir . '_buy')->where('uid', $uid)->where('cid', $id)->countAllResults();
    }
}